// axios二次封装实例
import request from '@/utils/request'

// 获取spu列表数据
export const reqSpuList = (page, limit, category3Id) => request({
  url: `/admin/product/${page}/${limit}`,
  method: 'GET',
  params: {
    category3Id
  }
})

// 获取品牌信息
export const reqTrademarkList = () => request({
  url: '/admin/product/baseTrademark/getTrademarkList',
  method: 'GET'
})

// 获取到spu销售属性
export const reqSaleAttrList = () => request({
  url: '/admin/product/baseSaleAttrList',
  method: 'GET'
})

// 通过spuid获取某一个spu的详细信息
export const reqSpu = (spuId) => request({
  url: `/admin/product/getSpuById/${spuId}`,
  method: 'GET'
})

// 获取spu照片
export const reqSpuImage = (spuId) => request({
  url: `/admin/product/spuImageList/${spuId}`,
  method: 'GET'
})

// 添加/修改spu信息(区别在于是否携带id)
export const reqAddOrUpdateSpu = (spu) => {
  if (spu.id) {
    // 更新spu
    return request({
      url: '/admin/product/updateSpuInfo',
      method: 'POST',
      data: spu
    })
  } else {
    // 添加spu
    return request({
      url: '/admin/product/saveSpuInfo',
      method: 'POST',
      data: spu
    })
  }
}

// 删除spu
export const reqDeleteSpu = (spuId) => request({
  url: `/admin/product/deleteSpu/${spuId}`,
  method: 'DELETE'
})

// spu页面中添加sku页面接口
// 获取spu照片
export const reqSpuImageList = (spuId) => request({
  url: `/admin/product/spuImageList/${spuId}`,
  method: 'GET'
})

// 获取spu销售属性列表
export const reqSpuSaleAttrList = (spuId) => request({
  url: `/admin/product/spuSaleAttrList/${spuId}`,
  method: 'GET'
})

// 获取平台属性
export const reqAttrInfoList = (category1Id, category2Id, category3Id) => request({
  url: `/admin/product/attrInfoList/${category1Id}/${category2Id}/${category3Id}`,
  method: 'GET'
})

// 保存sku
export const reqSaveSkuInfo = (skuInfo) => request({
  url: '/admin/product/saveSkuInfo',
  method: 'POST',
  data: skuInfo
})

// 获取sku列表数据的接口
export const reqSkuList = (spuId) => request({
  url: `/admin/product/findBySpuId/${spuId}`,
  method: 'GET'
})
